<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.dao.CommonDAO"%>
<%@page import="com.util.Info"%>
<%@page import="com.model.Menuinfo"%>
<%@page import="com.model.Userrole"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>管理页面</title>
<!-- 调用CSS，JS -->
<link href="/wearablehealthymonitorsys/admin/images/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	font-family: "宋体";
	font-size: 12px;
	color: #333333;
	background-color: ;
}
.STYLE1 {
	color: #333333;
	font-size: x-large;
	font-family: Arial, Helvetica, sans-serif;
}
-->
</style>
<script language="javascript">
function window.onload() { 

if(top.location != self.location){ 

var a = window.parent.document.getElementsByTagName('iframe'); 

for (var i=0; i<a.length; i++){ 

if (a[i].name == self.name) {a[i].height = document.body.scrollHeight+320; return;}}} 
} 
</script>
<script language=javascript>
function show(no)
{
for(var i=1;i<20;i++)
{
var a = document.getElementById(no+"@"+i);
if(a==null)
{
continue;
}
if(a.style.display=="")
{
a.style.display="none";
}else{
a.style.display="";
}
}

}
</script>
<script type="text/javascript">
function showzhi(inn)
{
var a = document.getElementById("loca");
a.innerHTML=inn;
}
function change(no)
{
var c = document.getElementById("c");
c.innerHTML=no;
}
</script>

</head>
<body>

<%
  CommonDAO dao = (CommonDAO)Info.getDao(request,"CommonDAO");
  String utype = request.getParameter("utype");
  if(utype==null)utype = (String)request.getAttribute("utype");
  if(utype.equals("1")){
	  utype = "管理员";
  }else if(utype.equals("2")){
	  utype = "医生";
  }else{
	  utype = "护工";
  }
  String hql = " from Menuinfo where 1=1 order by id ";
  String hql2 = " from Userrole where utype='"+utype+"'";
   %>
					<form  name="f1" method="post" action="roleEdit.action?utype=<%=utype %>" onsubmit="return ck()">
					
						<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#BBD3EB">
						<%ArrayList<Menuinfo> list= (ArrayList<Menuinfo>)dao.findByHql(hql);
						ArrayList<Userrole> list2= (ArrayList<Userrole>)dao.findByHql(hql2); 
						String rrr = "-";
						for(Userrole ur:list2){
							rrr+=ur.getRole()+"-";
						}
						for(Menuinfo mi:list){
							System.out.println(mi.getId());
							
						%>
                          	<tr>
                            	<td bgcolor="#FFFFFF">&nbsp;&nbsp;&nbsp;
                            	<input type="checkbox" id="roles" name="roles" value="<%=mi.getId() %>" <%if(rrr.indexOf("-"+mi.getId().toString()+"-")!=-1){out.print("checked==checked");} %>/><%=mi.getMenuname() %>
                            	</td>
    						</tr>
                         <%} %>	
                         	<tr>
    							<td bgcolor="#FFFFFF" colspan="2">&nbsp;&nbsp;&nbsp;<input type="submit" value="提交"/></td>
    						</tr>
                            <script language="javascript">
                            	function ck(){
                            	var a = 0;
								var b = document.getElementsByName("roles");
									for(var i=0;i<b.length;i++){
										if(b[i].checked==true){
											a++;
										}
									}
									if(a==0){
											alert("至少选择一项权限");
											return false;
									}
                            }
<%
String suc = (String)request.getAttribute("suc");
if(suc!=null)
{
 %>
 alert("操作成功");
location.replace("/wearablehealthymonitorsys/admin/rolemgr.jsp");
 <%}%>
                            </script>
</table>      
</form>                 
</body>
</html>
